define(['jquery', 'mn', 'cm'], function () {
    $('footer').load('../html/footer.html')
    class details {
        constructor() {
            var user = getCookie('用户')
            var users = JSON.parse(localStorage.getItem('curt'))
            var jugement = users.findIndex((item) => {
                return item.userName == user
            })
            this.data = JSON.parse(localStorage.getItem('detail'))
            this.datas = JSON.parse(localStorage.getItem('shop' + jugement)) || []
            this.detailsId = this.data.goods_id
            this.num = 0
            console.log(this.detailsId);
            this.init()
        }
        init() {
            this.share()
            this.click()
            this.jude()
        }
        jude() {
            console.log($('.login'))
            if (getCookie('用户')) {
                let cookie = getCookie('用户')
                $('.login').html(`<a href="../html/member.html">${cookie}<img src="../imgaes/index/钻石.png" alt=""></a>`)
            }
        }
        share() {
            console.log(this.data)

            let thingName = `<p>${this.data.title}</p>`
            $('#firstImg').html(`<img src=${this.data.img_small_logo}>`)
            $('.rightBox .bottom .price').html(`秒杀价<span class='nowPrice'>${this.data.current_price}</span><span class="pastPrice">${this.data.price}</span></span>`)
            $('#topNav .middle').html(`<p>首页>商品详情>${this.data.title}</p> <div class='contact'><p>联系客服</p></div>`)
            // $("#hole .leftBox").append(str)
            $("#hole .rightBox .name").append(thingName)
            let Data = this.datas.find((item) => {
                return this.detailsId == item.goods_id
            })
            console.log(Data);
            $('#hole .buy .right input').val(`${this.num}`)
            $('#hole .buy .right .add').click(() => {
                this.num++
                $('#hole .buy .right input').val(`${this.num}`)
            })
            $('#hole .buy .right .sub').click(() => {
                if (this.num <= 0) {
                    alert('您不能再减少了噢')
                }
                else {
                    this.num--
                    $('#hole .buy .right input').val(`${this.num}`)
                }
            })
            $('#hole .buy .right .txt').blur(()=>{
                if ($('#hole .buy .right .txt').val() > 0) {
                    this.num = Number($('#hole .buy .right .txt').val())
                    console.log(this.num);
                }
                else{
                    alert('请您输入大于0的数字噢')
                }
            })
        }
        click() {
            let Data = this.datas.find((item) => {
                return this.detailsId == item.goods_id
            })
            var user = getCookie('用户')
            var users = JSON.parse(localStorage.getItem('curt'))
            var jugement = users.findIndex((item) => {
                return item.userName == user
            })
            $('.buyNow').click(() => {
                if (this.num > 0) {
                    // Data.cart_number += this.num
                    let jude = this.datas.find((item) => {
                        return this.detailsId == item.goods_id
                    })
                    if (jude) {
                        var i = this.datas.findIndex(item => {
                            return item.goods_id == this.detailsId
                        })
                        this.datas[i].cart_number += this.num
                    }
                    else {
                        this.data.cart_number += this.num
                        this.datas.push(this.data)
                        // console.log(444)
                    }
                    console.log(this.datas);
                    localStorage.setItem('shop' + jugement, JSON.stringify(this.datas))
                    self.location = 'getPrice.html'
                }
                else {
                    alert('您需要买一点东西噢')
                }
            })

        }
    }
    new details()
    $(function () {

        var magnifierConfig = {
            magnifier: "#magnifier1",//最外层的大容器
            width: 520,//承载容器宽
            height: 520,//承载容器高
            moveWidth: null,//如果设置了移动盒子的宽度，则不计算缩放比例
            zoom: 2//缩放比例
        };

        var _magnifier = magnifier(magnifierConfig);
    });
})

